#include <iostream>
#include <algorithm>
#include <vector>

int const maxn = 102;

bool map[maxn][maxn];
int greater[maxn];

int n, m;

int main()
{
	std::cin >> n >> m;
	for (int i = 0, x, y; i < m; i++) {
		std::cin >> x >> y;
		map[--x][--y] = true;
	}

	for (int k = 0; k < n; k++)
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				if (map[i][k] && map[k][j]) map[i][j] = true;

	std::vector<int> greater_count;
	for (int i = 0; i < n; i++) {
		int count = 0;
		for (int j = 0; j < n; j++) if (map[j][i]) count++;
		greater_count.push_back(count);
		greater[count]++;
	}
	sort(greater_count.begin(), greater_count.end());
	int ans = 0;
	for (int i = 0; i < n; i++)
		if (greater_count[i] == i && greater[i] == 1) ans++;
	std::cout << ans << "\n";
}

